//
// CStreamSocket.h
//

#ifndef __H_CStreamSocket__
#define __H_CStreamSocket__

class CFilterNetReceiver;
class CStreamSocket
{
protected:
	SOCKET		mSocket;
	BOOL		mIsConnected;

	BOOL		mIsReceiving;  // For receiving
	HANDLE		mRcvThread;

	BOOL		mIsSending;    // For sending
	HANDLE		mSndThread;

	CFilterNetReceiver * mOwnerFilter;

public:
	CStreamSocket();
	virtual ~CStreamSocket();

	void SetOwnerFilter(CFilterNetReceiver * inFilter);

public:
	BOOL Attach(SOCKET inSocket);
	void Detach(void);
	SOCKET GetSocket(void);

	BOOL ConnectTo(DWORD inTargetIP, WORD inPort);
	BOOL IsConnected(void) { return mIsConnected; };

	// Receive functions
	BOOL StartReceiving(void);
	void StopReceiving(void);
	BOOL IsReceiving(void) { return mIsReceiving; };

	// Send functions
	BOOL StartSending(void);
	void StopSending(void);
	BOOL IsSending(void) { return mIsSending; };

protected:
	static DWORD WINAPI ReceivingThrd(void * pParam);
	static DWORD WINAPI SendingThrd(void * pParam);

	virtual void ReceivingLoop(void);
	virtual void SendingLoop(void);
};

#endif // __H_CStreamSocket__